<?php
	defined('RUN') or die('No access');

	class WebsiteModel
	{
		public function getLayoutData()
		{
			$data = array();
            //update
            $sql = ("SELECT ngay FROM `temp`");
            $query = Db::query($sql);
            $result = Query::fetch($query);
   
            if($result['ngay'] < date('Y-m-d')){
                $dulieu = array('ngay' => date('Y-m-d'));                
                $condition = array('field' => 'id','value' => 1);
                Model::updateData('temp', $dulieu, $condition);
                
                $product= Model::getDataSql("SELECT * FROM `product` WHERE `end` >= ".date('Y-m-d'));                
                foreach($product as $row){
                    $member = Model::get('member')->getById($row['member_id'],'`pay`');
                    $dulieu = array('pay' => $member['pay']- $row['pay']);                
                    Model::get('member')->update($dulieu, $row['member_id']);
                }
                
                
            }
            $product= Model::getDataSql("SELECT * FROM `product` WHERE `end` > date(2000-01-01) AND `end` < '".date('Y-m-d')."'"); 
                foreach($product as $row){
                    $dulieu = array(
                        'pay'   => 0,
                        'start' => 0,
                        'end'   => 0,
                    );                
                    Model::get('product')->update($dulieu, $row['id']);
                }
            
            
            if(isset($_SESSION['member'])){
                $id = $_SESSION['member']['id']; 
                $data['webmember'] = Model::get('member')->getById($id,'`name`,`pay`');
            }
            
			$data['categories'] = Model::get('product_category')->getCategory();
			$data['config'] = Model::get('config')->getById(1);
			//support
			$fields='`name`,`yahoo`,`skype`';
			$data['supports'] = Model::get('support')->getSupports($fields);
			//counter
			$data['counter_onl']=Model::get('counter')->show_online();
			$data['counter_ye']=Model::get('counter')->show_yesterday();
			$data['counter_we']=Model::get('counter')->show_weekday();
			$data['counter_all']=Model::get('counter')->show_all();
			//adv
			$data['adv_left']=Model::get('adv')->getAdvs('`name`,`link`,`images`',1);
			$data['adv_right']=Model::get('adv')->getAdvs('`name`,`link`,`images`',2);
			
			$data['lastest_posts'] = Model::get('post')->getLastest(3);
			$data['lang'] = Language::getLanguageCode();
			$data['temp'] = UserAgent::isBot() ? 'temp' : 'default';
			return $data;
		}
		
	}

